﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;

/// <Summary> 
/// Here we create an actual game
/// like select Level to play, 
/// play time, name of the session etc
/// then we host the game which other players find through 
/// JoinSession
/// </Summary> 

namespace Imagine
{
    class CreateSession : GameScreen
    {
       public override bool Init(object extraData)
       {

           return true; 
       }
       public override bool Draw(GameTime gameTime, SpriteBatch spriteBatch)
       { 
           Engine.Instance().GraphicsDevice.Clear(Color.Green);
           spriteBatch.DrawString(Engine.Instance().SpriteFont, "CreateSessionScreen", new Vector2(200,0),Color.Chocolate);
           spriteBatch.DrawString(Engine.Instance().SpriteFont, "Create game", new Vector2(300,240), Color.Chocolate);
           return true; 
       }
       public override bool Update(GameTime gameTime)
       { 
           if(InputManager.Instance().IsKeyDown(Keys.Enter))
           {
               //Set Up Dummy GamePlayParams and store them in NetworkSessionProperties
               SetUpGamePlayParams();
               //Now Create the Actual Session, this will attach the NetworkSessionProperties with the Session
               NetworkManager.Instance().CreateSession();

               //OOPs we cant have it here
               //ScreenManager.Instance().SetScreen(ImagineScreens.eLobbyScreen, ScreenState.Dead, null);
           }
           
           return true; 
       }

       public override bool Release()
       { 
           return true; 
       }

        private void SetUpGamePlayParams()
        {
           //Fill In Dummy properties into GameplayInitparams
           GamePlayInitParams.LevelName = (int)Levels.eTest1;
           GamePlayInitParams.LevelTime = 0;
           GamePlayInitParams.MaxPlayers = 8;
           
            //Now attach them to the Session so that others can also use them 
            NetworkManager.Instance().GamePlayParams[(int)GamePlayInitParamsIndex.eLevelName ]  = 10; 
            NetworkManager.Instance().GamePlayParams[(int)GamePlayInitParamsIndex.eMaxPlayers]  = GamePlayInitParams.MaxPlayers; 
            NetworkManager.Instance().GamePlayParams[(int)GamePlayInitParamsIndex.eLevelTime ]  = GamePlayInitParams.LevelTime; 
            NetworkManager.Instance().GamePlayParams[(int)GamePlayInitParamsIndex.eFreezeTime]  = GamePlayInitParams.FreezeTime;

        }

    }
}

